package com.cn.demo4.servlet.admin.product;

import com.alibaba.fastjson.JSONObject;
import com.cn.demo4.service.IProductService;
import com.cn.demo4.service.impl.ProductServiceImpl;
import com.cn.demo4.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/product/del")
public class productDelServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        //得到前台传过来的数据
        //2.拿到前台传来的数据
        String idString = req.getParameter("id");

        //3.封装数据
        Integer id = Tool.stringToInt(idString);
        //4.调用服务逻辑层
        IProductService iProductService = new ProductServiceImpl();
        //5.得到数据(返回的结果是影响条数)
        int result = iProductService.del(id);

        //6.返回数据
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",result);
        resp.getWriter().println(jsonObject);
    }
}
